Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a macro that provides a more consise way of recording a new value for a field.
Motivation
The ability to record updated values for a span is very useful. However, it can be a bit verbose, and for what I assume is the most common scenario, adding fields to the current span, the update can quickly capture four lines in an already-busy function.
Here's an example from a code base I'm contributing to, with some names changed, using a helper function to format a
time::Instant
value inside of atracing::Span::record
call:Solution
My proposal is to add a way to record a field on the current span. This PR has one such implementation, which, using the code sample above, gives:
I'm open to other suggestions, of course, and if the maintainers agree that this is something that should be solved in the
tracing
package, I need some help figuring out where such an implementation belongs. This example implementation "feels" right astracing::field::record!
, but I've yet to fully understand how macro exports work.